package com.cat.dataStructure;

import java.util.ArrayDeque;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-deletions-to-make-array-beautiful/description/
 * @create 2025/9/9 09:56
 * @since JDK17
 */

public class Solution64 {
    public int minDeletion(int[] nums) {
        int ans = 0, n = nums.length;
        ArrayDeque<Integer> stack = new ArrayDeque<>();
        for (int i = 0; i < n; i++) {
            if (stack.size() % 2 == 0 || (stack.peek() != nums[i])) {
                stack.push(nums[i]);
            } else {    //
                ans++;
            }
        }

        return ans + stack.size() % 2;
    }
}
